<template>
  <div class="my-tag">
    <input
      class="input"
      type="text"
      placeholder="输入标签"
      v-model="name"
      v-if="edit"
      v-select
      @blur="show"
      @keyup.enter="show"
    />
    <div class="text" v-else @dblclick="isShow">{{ value }}</div>
  </div>
</template>

<script>
export default {
  props: {
    value: {
      type: [String, Number],
      require: true,
    },
  },
  data() {
    return {
      edit: false,
      name: '',
    }
  },
  methods: {
    isShow() {
      this.edit = true

      this.name = this.value
    },
    show() {
      this.edit = false

      this.$emit('input', this.name)
    },
  },
}
</script>

<style scoped lang="less">
.my-tag {
  cursor: pointer;
  .input {
    appearance: none;
    outline: none;
    border: 1px solid #ccc;
    width: 100px;
    height: 40px;
    box-sizing: border-box;
    padding: 10px;
    color: #666;
    &::placeholder {
      color: #666;
    }
  }
}
</style>
